﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HXDNB.DAL
{
    public class SaleOrderBLL : BaseDAL<SaleOrder>
    {
        public SaleOrderBLL() : base("SaleOrder") { }

        public IQueryable<SaleOrderList> GetList(DateTime? OrderDate, int Customer = -1, int ProductID = -1, int State = -1)
        {
            var list = from i in _e.SaleOrder
                       join j in _e.Product on i.ProductID equals j.ID into Temp
                       from t in Temp.DefaultIfEmpty()
                       join x in _e.Customer on i.CustomerID equals x.ID into C_temp
                       from y in C_temp.DefaultIfEmpty()
                       where (ProductID < 0 || i.ProductID == ProductID) && (State < 0 || i.State == State)
                         && (OrderDate == null || i.OrderTime == OrderDate) && (Customer < 0 || i.CustomerID == Customer)
                       orderby i.CreateTime descending
                       select new SaleOrderList
                       {
                           ID = i.ID,
                           AllPrice = i.AllPrice,
                           CreateTime = i.CreateTime,
                           Express = i.Express,
                           ExpressPrice = i.ExpressPrice,
                           Num = i.Num,
                           OtherPrice = i.OtherPrice,
                           Price = i.Price,
                           ProductID = i.ProductID,
                           ProductName = t.ProductName,
                           PayState = i.PayState,
                           Remarks = i.Remarks,
                           SendTime = i.SendTime,
                           State = i.State,
                           ReceivedMoneyTime = i.ReceivedMoneyTime,
                           CustomerID = i.CustomerID,
                           OrderTime = i.OrderTime,
                           CustomerName = y.Name
                       };
            return list.AsQueryable();
        }
    }
}
